home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / extend.exe / EXTEND.ASM < prev    next >
Assembly Source File  |  1989-03-09  |  9KB  |  230 lines

  1. ;   This is the source code for the replacement INT 21 handler EXTEND.PAS.
  2. ; This code is designed to be compiled by the TASM assembler and linked into
  3. ; the Pascal code.
  4. ;
  5. ;   This code was based upon earlier work by Randy Forgaard, Bela Lubkin and
  6. ; Kim Kokkonen.  The previous implementation was based on using the same
  7. ; technique only not using an interrupt handler.  See EXTEND.DOC for more
  8. ; information.
  9. ;
  10. ;   To compile with TASM:
  11. ;      TASM EXTEND
  12. ;
  13. ; Scott Bussinger
  14. ; Professional Practice Systems
  15. ; 110 South 131st
  16. ; Tacoma, WA  98444
  17. ; (206)531-8944
  18. ; Compuserve [72247,2671]
  19. ;
  20. COMMENT ~
  21.   ** Revision History **
  22.   1 EXTEND.ASM 9-Mar-89,`SCOTT' First version using TLIB -- Based on 3.2
  23.   ** Revision History **
  24. ~
  25. ; Version 3.2 --  9/25/1988 -- Changed EXTEND.ASM to compile under TASM (needed a few detail changes)
  26. ;         3.0 -- 10/26/1987 -- Reworked as a UNIT for use with Turbo Pascal 4
  27. ;                              EXTEND.ASM reworked to be compatible with A86 assembler
  28. ;         2.5 --  3/16/1987 -- EXTEND.ASM worked on by Kim Kokkonen and Brian Foley to work
  29. ;                                with Turbo Extender and whittle off a few clock cycles
  30. ;         2.4 -- 12/16/1986 -- Fixes problem with DUP function
  31. ;         2.3 -- 11/18/1986 -- EXTEND now only affects DOS calls made from
  32. ;                                same code segment it was installed from (fixes
  33. ;                                problems with EXEC and batch files and already
  34. ;                                resident TSR programs
  35. ;         2.2 -- 10/04/1986 -- Fixed problem with EXEC function destroying all
  36. ;                                registers including the stack
  37. ;                              Changed way that original handle number is kept
  38. ;                              Permit FORCEDUP to change a standard handle
  39. ;                              Improve some comments
  40. ;         2.1 -- 10/02/1986 -- Fixed problem of Turbo assuming registers valid
  41. ;                                after a call to DOS
  42. ;         2.0 -- 10/01/1986 -- Initial release of this inline code
  43. ;
  44.  
  45.         PUBLIC  ExtendInit,ExtendHandler
  46.  
  47. DSEG    SEGMENT WORD PUBLIC
  48.  
  49.         EXTRN   OldInt21:DWORD         ; Address of old INT 21 handler
  50.         EXTRN   PrefixSeg:WORD         ; Segment address of Pascal program's PSP
  51.  
  52. DSEG    ENDS
  53.  
  54.  
  55. CSEG    SEGMENT WORD PUBLIC
  56.  
  57.         ASSUME  CS:CSEG, DS:DSEG
  58.  
  59. ; CS relative Data Storage
  60.  
  61. HandleTable    DD ?                    ; Pointer to standard handle table in PSP
  62. IntVector      DD ?                    ; Provide CS relative storage for old INT 21 vector
  63. SaveFunction   DB ?                    ; Save DOS function number
  64. SaveHandle     DB ?                    ; Save original handle
  65. SaveLastDCB    DB ?                    ; Save original handle slot
  66.  
  67. ; Initialize a few CS relative variables
  68.  
  69. ExtendInit PROC NEAR
  70.         LES   AX,[OldInt21]            ; Get the original INT 21 vector into CS relative storage
  71.         MOV   WORD PTR CS:[IntVector],AX
  72.         MOV   WORD PTR CS:[IntVector+2],ES
  73.  
  74.         MOV   WORD PTR CS:[HandleTable],0018H ; Create a pointer to handle table in PSP
  75.         MOV   AX,[PrefixSeg]
  76.         MOV   WORD PTR CS:[HandleTable+2],AX
  77.         RET
  78.  
  79. ExtendInit ENDP
  80.  
  81.  
  82. ; Main replacement for INT 21 handler
  83.  
  84. ExtendHandler PROC FAR
  85.  
  86.         PUSH  BP                       ; Save BP
  87.  
  88.         MOV   BP,SP                    ; Make sure this call is from our program
  89.         MOV   BP,[BP+4]                ; BP = caller's CS
  90.         CMP   BP,WORD PTR CS:[HandleTable+2] ; Is the caller's CS < our PSP address
  91.         JB    IgnoreExtend
  92.         CMP   BP,DSEG                  ; Is the caller's CS < our data segment
  93.         JAE   IgnoreExtend
  94.  
  95.         POP   BP                       ; Restore BP
  96.  
  97.         CMP   AH,4BH                   ; Skip the rest of this if an EXEC function
  98.         JNE   NotEXEC
  99.  
  100. IgnoreExtend:
  101.         POP   BP                       ; Restore BP
  102.         JMP   CS:[IntVector]           ; Go to original handler
  103.  
  104. NotEXEC:
  105.         CMP   AH,46H                   ; Function $46 is only partially supported
  106.         JNE   ValidFunction
  107.         CMP   CL,4                     ; Permit FORCEDUP if it's a standard handle
  108.         JBE   ValidFunction
  109.  
  110. NotSupported:
  111.         MOV   AX,6                     ; Tell the user it's an invalid handle
  112.         STC                            ; Signal an error
  113.         JMP   ReturnToTurbo
  114.  
  115. ValidFunction:
  116.         PUSH  DS                       ; Set up pointer to handle table
  117.         PUSH  CX
  118.         PUSH  DI
  119.         LDS   DI,CS:[HandleTable]
  120.         MOV   CL,[DI+19]               ; Remember contents of last handle slot
  121.         MOV   CS:[SaveLastDCB],CL
  122.         MOV   CS:[SaveFunction],AH     ; Save function code for later
  123.  
  124.         CMP   AH,3EH                   ; Check for DOS functions that pass a handle
  125.         JB    CallOldInt21
  126.  
  127.         CMP   AH,40H                   ; Convert functions $3E..$40 (Close,Read,Write)
  128.         JBE   ConvertDCB
  129.  
  130.         CMP   AH,42H                   ; Convert function $42 (Seek)
  131.         JE    ConvertDCB
  132.  
  133.         CMP   AH,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  134.         JB    CallOldInt21
  135.  
  136.         CMP   AH,46H
  137.         JBE   ConvertDCB
  138.  
  139.         CMP   AH,57H                   ; Convert function $57 (File time/date)
  140.         JE    ConvertDCB
  141.  
  142.         CMP   AH,5CH                   ; Convert function $5C (Lock/Unlock)
  143.         JE    ConvertDCB
  144.  
  145.         CMP   AH,68H                   ; Convert function $68 (Commit File)
  146.         JNE   CallOldInt21
  147.  
  148. ConvertDCB:
  149.         MOV   CS:[SaveHandle],BL       ; Save the original handle
  150.         CMP   BL,4                     ; Check for output to standard handle
  151.         JBE   CallOldInt21             ; Let calls with standard handle pass through
  152.  
  153.         SUB   BL,5                     ; Account for an offset of 5 in DCB number
  154.         MOV   [DI+19],BL               ; Stuff DCB into last handle slot
  155.         MOV   BL,19                    ; Use number of last handle slot
  156.  
  157. CallOldInt21:
  158.         POP   DI                       ; Restore the registers
  159.         POP   CX
  160.         POP   DS
  161.         PUSHF
  162.         CALL  CS:[IntVector]           ; Fake an INT21 to original handler
  163.         STI                            ; Allow interrupts
  164.  
  165.         PUSH  DS                       ; Setup pointer to handle table
  166.         PUSH  DI
  167.         PUSH  BX
  168.         LDS   DI,CS:[HandleTable]      ; Check if INT handler returned an error
  169.         JC    Done                     ; Possibly needs to goto CheckForHandle??
  170.  
  171.         MOV   BL,CS:[SaveFunction]     ; Check for return handles
  172.         CMP   BL,3CH                   ; Convert function $3C (Create)
  173.         JE    ConvertHandle
  174.         CMP   BL,3DH                   ; Convert function $3D (Open)
  175.         JE    ConvertHandle
  176.         CMP   BL,45H                   ; Convert function $45 (Dup)
  177.         JE    ConvertHandle
  178.         CMP   BL,5AH                   ; Convert function $5A (Create unique)
  179.         JE    ConvertHandle
  180.         CMP   BL,5BH                   ; Convert function $5B (Create new)
  181.         JE    ConvertHandle
  182.         CMP   BL,68H                   ; Convert function $68 (Commit file)
  183.         JNE   CheckForHandle
  184.  
  185. ConvertHandle:
  186.         MOV   BX,AX                    ; Use handle as offset into handle table
  187.         MOV   AL,0FFH                  ; Show the handle as unused
  188.         XCHG  AL,[DI+BX]               ; Return DCB as handle number
  189.         ADD   AL,5                     ; Use offset of 5 to avoid standard handles
  190.  
  191. CheckForHandle:
  192.         MOV   BL,CS:[SaveFunction]     ; Check for handles left in registers
  193.         CMP   BL,3FH                   ; Convert function $3F (Read)
  194.         JE    RestoreHandle
  195.         CMP   BL,40H                   ; Convert function $40 (Write)
  196.         JE    RestoreHandle
  197.         CMP   BL,42H                   ; Convert function $42 (Seek)
  198.         JE    RestoreHandle
  199.         CMP   BL,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  200.         JB    Succes